package exam.wzb.jsp.dao.impl;

import exam.wzb.jsp.dao.BookDao;
import exam.wzb.jsp.model.Book;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.List;

public class BookDaoImpl implements BookDao {

    private SqlSessionFactory sqlSessionFactory;

    public BookDaoImpl(SqlSessionFactory sqlSessionFactory) {
        this.sqlSessionFactory = sqlSessionFactory;
    }

    @Override
    public List<Book> findBooks(String name) {
        try (SqlSession session = sqlSessionFactory.openSession()) {
            // 这里使用MyBatis的Mapper来执行查询
            return session.selectList("BookMapper.findBooks", name);
        }
    }

    @Override
    public void deleteBook(Integer id) {
        try (SqlSession session = sqlSessionFactory.openSession()) {
            session.delete("BookMapper.deleteBook", id);
            session.commit();
        }
    }

    @Override
    public List<Book> findBooksByPage(int offset, int limit) {
        return null;
    }

    // 实现其他方法...
}
